package com.lex.manager.service.impl;

import com.lex.manager.dao.UserCustomerMapper;
import com.lex.manager.dao.UserMapper;
import com.lex.manager.pojo.dto.PageParam;
import com.lex.manager.pojo.dto.UserCustomer;
import com.lex.manager.pojo.dto.UserResult;
import com.lex.manager.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class UserServiceImpl implements UserService{
    @Autowired
    private UserCustomerMapper userDao;

    @Override
    public UserResult<UserCustomer> getUserResultByPage(PageParam pageParam) {
        UserResult<UserCustomer> userResult=new UserResult<>();
        userResult.setLimit(pageParam.getRows());
        userResult.setPage(pageParam.getPage());
        int total=userDao.getCountPage();
        userResult.setTotal(total);
        userResult.setPages((int) Math.ceil(1.0*total/(pageParam.getRows())));
        List<UserCustomer> docs=userDao.getDocsByPage(pageParam);
        userResult.setDocs(docs);
        return userResult;
    }
}
